package org.asg.dis.model;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.Instant;

@Data
@NoArgsConstructor  // 添加无参构造器以便于反序列化
public class ApiResponse<T> {
    private T data;
    private String message;
    private int status;
    private long timestamp;

    public ApiResponse(T data, String message, int status, long timestamp) {
        this.data = data;
        this.message = message;
        this.status = status;
        this.timestamp = timestamp;
    }


    public static <T> ApiResponse<T> ok(T data) {
        return new ApiResponse<>(data, "成功", 200, Instant.now().toEpochMilli());
    }
    public static <T> ApiResponse<T> ok() {
        return new ApiResponse<>(null, "成功", 200, Instant.now().toEpochMilli());
    }
    public static ApiResponse<String> error(int status, String message) {
        return new ApiResponse<>(null, message, status, Instant.now().toEpochMilli());
    }

    public static <T> ApiResponse<T> created(T data) {
        return new ApiResponse<>(data, "创建成功", 201, Instant.now().toEpochMilli());
    }

    public static ApiResponse<String> notFound(String message) {
        return error(404, message);
    }

    public static ApiResponse<String> badRequest(String message) {
        return error(400, message);
    }
}

